package com.acegear.horizon.domain.models.jpa;

import com.fasterxml.jackson.annotation.JsonIgnore;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import ch.hsr.geohash.GeoHash;

/**
 * Created by wangsike on 2016/12/21.
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Location {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@JsonIgnore
	private Long id;

	@Column
	private Double latitude;

	@Column
	private Double longitude;

	@Column
	private String geoHash;

	@CreatedDate
	@Column
	private Long createAt;

	@LastModifiedDate
	@Column
	private Long updateAt;

	public Location() {
	}

	public Location(Double latitude, Double longitude) {
		this.latitude = latitude;
		this.longitude = longitude;
		this.geoHash = GeoHash.geoHashStringWithCharacterPrecision(latitude, longitude, 12);
	}

	public Long getCreateAt() {
		return createAt;
	}

	public Long getUpdateAt() {
		return updateAt;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public String getGeoHash() {
		return geoHash;
	}

	public void setGeoHash(String geoHash) {
		this.geoHash = geoHash;
	}

	public void setCreateAt(Long createAt) {
		this.createAt = createAt;
	}

	public void setUpdateAt(Long updateAt) {
		this.updateAt = updateAt;
	}

	public void update(Location other) {
		this.latitude = other.getLatitude();
		this.longitude = other.getLongitude();
		this.geoHash = other.getGeoHash();

	}

}
